home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 8: LINUX Games / Linux Cubed Series 8 - LINUX Games.iso / games / strategy / tictac2-.000 / tictac2- / tictac2 / main.c < prev    next >
C/C++ Source or Header  |  1980-01-04  |  6KB  |  127 lines

  1. /*****************************************************************************.
  2. **  TicTac2:  Simple TicTacToe two-player game against another user or cpu.  **
  3. **  Copyright (c) 1995 Ian Singh                                             **
  4. **                                                                           **
  5. **  This program is free software; you can redistribute it and/or modify it  **
  6. **  under the terms  of the  GNU General Public License as published by the  **
  7. **  Free Software Foundation;  either version 2 of the License, or (at your  **
  8. **  option) any version later.                                               **
  9. **                                                                           **
  10. **  This program is distriubted in the hope that it  will  be  useful,  but  **
  11. **  WITHOUT   ANY   WARRANTY;   without   even   the  implied  warranty  of  **
  12. **  MERCHANTABILITY or FITNESS FOR  A  PARTICULAR  PURPOSE.   See  the  GNU  **
  13. **  General Public License for more details.                                 **
  14. **                                                                           **
  15. **  You should have received a copy of the GNU General Public License along  **
  16. **  with  this  program;   if not,  write  to the Free Software Foundation,  **
  17. **  Inc.,  675 Mass Ave, Cambridge, MA 02139, USA.                           **
  18. **                                                                           **
  19. **  Ian Singh                           Ian Singh                            **
  20. **  am256@freenet.carleton.ca           3G Arnold Dr.                        **
  21. **                                      Nepean, Ontario                      **
  22. **                                      K2H 6V6                              **
  23. .*****************************************************************************/
  24.  
  25. /* +-----------------------------------------------------------------------+ **
  26. ** |                                                                          | **
  27. ** |  main.c:  well, main stuff.                       | **
  28. ** |                                                                       | **
  29. ** +-----------------------------------------------------------------------+ */
  30.  
  31. #include <stdio.h>
  32. #include <ncurses/ncurses.h>
  33. #include "tictac2.h"
  34. #include "screen.h"
  35. #include "moves.h"
  36.  
  37. void usage_exit();
  38. void show_gnu_license();
  39.  
  40. void main(int argc, char *argv[] )
  41. {
  42.    int gameover=0,i;
  43.    player player1 = { HUMAN_YOU, 1 };
  44.    player player2 = { UNDEFINED, 10 };
  45.    char field[9] = {0,0,0,0,0,0,0,0,0}; 
  46.    char s[50];
  47.  
  48.    if ( argc<2 )  usage_exit(); 
  49.    if ( !strcasecmp(argv[1],"me") 
  50.         || !strcasecmp(argv[1],"-me") ) player2.status=HUMAN_YOU;
  51.    else if ( !strcasecmp(argv[1],"cpu")
  52.         || !strcasecmp(argv[1],"-cpu") ) player2.status=CPU;
  53.    else {
  54.      /* multi-user initalization stuff goes here... */
  55.    }
  56.  
  57.    setup_terminal_stuff(); 
  58.  
  59.    mvaddstr(6,35,"Playing with:");
  60.    attrset(A_STANDOUT); 
  61.    switch(player2.status)  {
  62.    case HUMAN_YOU: mvaddstr(6,35+14,"yourself!");  break;
  63.    case CPU:       mvaddstr(6,35+14,"mr. computer.");  break;
  64.    case HUMAN_THEM: mvaddstr(6,35+14,"someone else.");  break;
  65.    }
  66.  
  67.    while (1)  {
  68.      getmove(player1, field);  
  69.      refresh_board(field);
  70.      if ( gameover=checkwin(field) ) break;  
  71.      getmove(player2, field);  
  72.      refresh_board(field);
  73.      if ( gameover=checkwin(field) )  break; 
  74.    
  75.    }
  76.    if ( gameover==3 )
  77.      sprintf(s,"Nobody won... you both must suck...");
  78.    else if ( gameover==1 )
  79.      sprintf(s,"You won.. you rule.. %d",gameover);
  80.    else if ( gameover==10 )
  81.      sprintf(s,"you didn't win... you suck :-) %d",gameover); 
  82.    center(23,0,79,s);
  83.    center(24,0,79,"Press any key to Leave...");
  84.    getch();
  85.    kill_terminal_stuff();
  86.    show_gnu_license();
  87.    
  88. }
  89.  
  90. void usage_exit()
  91. {
  92.   fprintf(stderr,"usage: tictac2 user [tty]\n"
  93. "where user is one of:  me          -- play against your self\n"
  94. "                       cpu         -- play against computer\n" 
  95. "                       user        -- play against another user[doesn't work]\n");
  96.   exit(1);
  97. }
  98.  
  99. void show_gnu_license()
  100. {
  101. char gnu[]=""
  102. "\n\nTicTac2:  Simple TicTacToe two-player game against another user or cpu.\n"
  103. "Copyright (c) 1995 Ian Singh\n"                            
  104. "\n"                                                                          
  105. "This program is free software; you can redistribute it and/or modify it\n"  
  106. "under the terms  of the  GNU General Public License as published by the\n"  
  107. "Free Software Foundation;  either version 2 of the License, or (at your\n"  
  108. "option) any version later.\n"                                               
  109. "\n"                                                                         
  110. "This program is distriubted in the hope that it  will  be  useful,  but\n"  
  111. "WITHOUT   ANY   WARRANTY;   without   even   the  implied  warranty  of\n"  
  112. "MERCHANTABILITY or FITNESS FOR  A  PARTICULAR  PURPOSE.   See  the  GNU\n"  
  113. "General Public License for more details.\n"                                 
  114. "\n"                                                                         
  115. "You should have received a copy of the GNU General Public License along\n"  
  116. "with  this  program;   if not,  write  to the Free Software Foundation,\n"  
  117. "Inc.,  675 Mass Ave, Cambridge, MA 02139, USA.\n"                          
  118. "\n"                                                                        
  119. "  Ian Singh                           Ian Singh\n"                            
  120. "  am256@freenet.carleton.ca           3G Arnold Dr.\n"                        
  121. "                                      Nepean, Ontario\n"                   
  122. "                                      K2H 6V6\n\n"
  123. "Have a nice day...";                              
  124.  
  125. puts(gnu);
  126. }
  127.